package com.xiaoshuidi.cloud.module.rooms.controller.app.device;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.iot.api.device.vo.AddPassword;
import com.xiaoshuidi.cloud.module.iot.api.device.vo.AmmeterReportRes;
import com.xiaoshuidi.cloud.module.iot.api.device.vo.WaterMeterReportRequest;
import com.xiaoshuidi.cloud.module.iot.api.device.vo.WaterMeterReportResponse;
import com.xiaoshuidi.cloud.module.rooms.controller.app.device.vo.AmmeterInfoVO;
import com.xiaoshuidi.cloud.module.rooms.controller.app.device.vo.DoorLockInfoVO;
import com.xiaoshuidi.cloud.module.rooms.controller.app.device.vo.WaterMeterVO;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.AppDeviceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(ApiConstants.NAME + "/device")
@RequiredArgsConstructor
public class DeviceController {

    private final AppDeviceService appDeviceService;

    /**
     * 电表详情
     *
     * @return
     */
    @PostMapping("/ammeter/information")
    public CommonResult<List<AmmeterInfoVO>> findAmmeterInfo() {
        List<AmmeterInfoVO> ammeterInfo = appDeviceService.findAmmeterInfo();
        return CommonResult.success(ammeterInfo);
    }

    /**
     * 电表明细
     *
     * @param ammeterReportReqVO
     * @return
     */
    @PostMapping("/ammeter/report")
    public CommonResult<AmmeterReportRes> getAmmeterReport(@RequestBody WaterMeterReportRequest ammeterReportReqVO) {
        AmmeterReportRes ammeterReportRes = appDeviceService.getAmmeterReport(ammeterReportReqVO);
        return CommonResult.success(ammeterReportRes);

    }

    /**
     * 查询水表详情
     *
     * @return
     */
    @PostMapping("waterMeter/information")
    public CommonResult<List<WaterMeterVO>> getWaterMeterInfo() {
        List<WaterMeterVO> waterMeterVOList = appDeviceService.getWatermeterInfo();
        return CommonResult.success(waterMeterVOList);
    }

    /**
     * 用水明细
     *
     * @param waterMeterReportRequestModel
     * @return
     */
    @PostMapping("/waterMeter/report")
    public CommonResult<WaterMeterReportResponse> getWatermeterReport(@RequestBody WaterMeterReportRequest waterMeterReportRequestModel) {
        WaterMeterReportResponse waterMeterReportResponse = appDeviceService.getWatermeterReport(waterMeterReportRequestModel);
        return CommonResult.success(waterMeterReportResponse);

    }

    /**
     * 查询门锁详情
     *
     * @return
     */
    @PostMapping("/doorLock/information")
    public CommonResult<List<DoorLockInfoVO>> getDoorlockInfo() {
        List<DoorLockInfoVO> doorLockInfoVOS = appDeviceService.getDoorlockInfo();
        return CommonResult.success(doorLockInfoVOS);
    }

    /**
     * 门锁密码列表
     *
     * @param deviceNo
     * @return
     */
    @PostMapping("/doorLock/passwordList")
    public CommonResult<List<AddPassword>> getPasswordList(@RequestParam("deviceNo") String deviceNo,@RequestParam("mobile") String mobile) {
        List<AddPassword> list = appDeviceService.getPasswordList(deviceNo,mobile);
        return CommonResult.success(list);
    }

    /**
     * 修改密码
     *
     * @param addPasswordModel
     * @return
     */
    @PostMapping("/doorLock/updatePassword")
    public CommonResult<AddPassword> updatePassword(@RequestBody AddPassword addPasswordModel) {
        AddPassword addPassword = appDeviceService.updatePassword(addPasswordModel);
        return CommonResult.success(addPassword);
    }

}
